package com.itheima.health.controller;

import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import io.swagger.annotations.*;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "检查项目管理")
public class CheckItemController {

    @Reference
    CheckItemService checkItemService;

    @GetMapping("checkitem/findAll")
    @ApiOperation(value = "查询检查项方法",notes = "查询所有的检查项列表信息")
    public Result findAll(){
        return new Result(checkItemService.findAll());
    }

    @PostMapping("checkitem/findPage")
    @ApiOperation(value = "套餐查询",notes = "分页套餐查询")//  上述注解 添加在目标方法上！
    @ApiImplicitParams({
            @ApiImplicitParam(name="currentPage",value="当前分页页码",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="queryString",value="查询条件",required=false,paramType="form",dataType="String")
    })
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = checkItemService.findPage(queryPageBean);
        return  new Result(pageResult);
    }

    @PostMapping("checkitem/addCheckItem")
    public Result insertCheckItem(@RequestBody CheckItem checkItem){
        return new Result(checkItemService.saveOrUpdate(checkItem));
    }

    @DeleteMapping("checkitem/deleteCheckItem/{id}")
    public Result deleteCheckItem(@PathVariable int id){
        CheckItem checkItem = new CheckItem();
        checkItem.setId(id);
        checkItem.setIs_delete(1);
        return new Result(checkItemService.updateById(checkItem));
    }

}
